package com.weixing.mall.provider.manager;

import cn.hutool.core.collection.CollUtil;
import com.weixing.mall.provider.mapper.MemberMapper;
import com.weixing.mall.provider.mapper.MemberMessageMapper;
import com.weixing.mall.provider.mapper.OrderMapper;
import com.weixing.mall.provider.model.domain.Member;
import com.weixing.mall.provider.model.domain.MemberMessage;
import com.weixing.mall.push.PushMsg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @ClassName AgentAuditOrderManager
 * @Description
 * @Author Small
 * @Date 2021/1/25 10:39
 * @Version 1.0
 **/
@Component
public class AgentAuditOrderManager {
    @Autowired
    private OrderMapper orderMapper;
    @Autowired
    private MemberMessageMapper memberMessageMapper;
    @Autowired
    private MemberMapper memberMapper;

    public List<String> needAuditList(){
        return orderMapper.needAuditList();
    }

    public void recordMsg(List<String> auditList, PushMsg pushMsg) {

        if (CollUtil.isNotEmpty(auditList)){
            MemberMessage msg = null;
            for (String cid: auditList){
                Member member = memberMapper.selectByCid(cid);
                if (null != member){
                    msg = new MemberMessage();
                    msg.setAgentId(member.getAgentId());
                    msg.setMsg(pushMsg.getBody());
                    msg.setTitle(pushMsg.getTitle());
                    msg.setMsgType(2);
                    memberMessageMapper.insert(msg);
                }

            }
        }
    }
}
